{%extends 'admin/base.html'%}
{% import '_macros.html' as macros %}

{%block content%}
<div class="col-xs-12">
    <!-- PAGE CONTENT BEGINS -->


    <div class="table-responsive">
    <form id="delCommentsForm" method="post" action="/admin/manage-posts/delete-posts">
        <input id="commentIds" name="commentIds" type="hidden" value="-1">
    </form>
    <div class="btn-group pull-right">
        <button type="button" class="btn btn-danger" id="delComments">
          <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
        </button>
      </div>
        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th class="center">
                        <label>
                            <input type="checkbox" class="ace" />
                            <span class="lbl"></span>
                        </label>
                    </th>
                    <th>id</th>
                    <th>标题</th>
                    <th class="hidden-480">阅读次数</th>

                    <th>
                        <i class="icon-time bigger-110 hidden-480"></i>
                        插入时间
                    </th>
                    <th class="hidden-480">来源id</th>
                    <th class="hidden-480">管理</th>
                </tr>
            </thead>

            <tbody>

            {%for post in posts%}
                <tr>
                    <td class="center">
                        <label>
                            <input type="checkbox" class="ace op_check_com"  value="{{post.pid}}"/>
                            <span class="lbl"></span>
                        </label>
                    </td>

                    <td>
                        <a href="/p/{{post.pid}}">{{post.pid}}</a>
                    </td>
                    <td>{{post.title}}</td>
                    <td class="hidden-480">{{post.viewtimes}}</td>
                    <td>{{post.inserttime}}</td>

                    <td class="hidden-480">
                        <span class="label label-sm label-info">{{post.source}}</span>
                    </td>

                    <td class=" ">
                        <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                            <a class="red" onclick="delCommentCfm('/admin/manage-post/delete-post/{{post.pid}}')">
                                <i class="icon-trash bigger-130"></i>
                            </a>

                            <a class="green" href="/admin/edit_post/{{post.pid}}">
                                <i class="icon-pencil bigger-130"></i>
                            </a>

                            <a class="blue" href="/p/{{post.pid}}" target="_blank">
                                <i class="icon-zoom-in bigger-130"></i>
                            </a>
                        </div>

                        <div class="visible-xs visible-sm hidden-md hidden-lg">
                            <div class="inline position-relative">
                                <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
                                    <i class="icon-caret-down icon-only bigger-120"></i>
                                </button>

                                <ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">
                                    <li>
                                        <a class="tooltip-error" data-rel="tooltip" title="" data-original-title="Delete">
                                            <span class="red">
                                                <i class="icon-trash bigger-120"></i>
                                            </span>
                                        </a>
                                    </li>

                                    <li>
                                        <a class="tooltip-success" data-rel="tooltip" title="Edit">
                                            <span class="green">
                                                <i class="icon-edit bigger-120"></i>
                                            </span>
                                        </a>
                                    </li>

                                    <li>
                                        <a  class="tooltip-info" data-rel="tooltip" title="View">
                                            <span class="blue">
                                                <i class="icon-zoom-in bigger-120"></i>
                                            </span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </td>


                </tr>
            {%endfor%}

            </tbody>
        </table>
    </div>
    <div class="text-center">
    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, endpoint) }}
    </div>
    {% endif %}
    </div>

    <script src="/static/admin/js/jquery.dataTables.min.js"></script>
    <script src="/static/admin/js/jquery.dataTables.bootstrap.js"></script>
    <!-- 信息删除确认: For delete a comment confirm -->
    <div class="modal fade" id="delCommentCfmModel">
        <div class="modal-dialog">
            <div class="modal-content message_align">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">×</span></button>
                    <h4 class="modal-title">确认删除评论？</h4>
                </div>
                <div class="modal-body">
                    <p>
                        将该评论删除后不可恢复，您确认要删除吗？
                    </p>
                    <p>
                        （提示：如果您只是不想显示该评论内容，可以选择将其屏蔽，而不必删除。）
                    </p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a onclick="" id="delCommentCfmClick" class="btn btn-success" data-dismiss="modal">确定</a>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <!-- 信息删除确认: For select comments confirm -->
    <div class="modal fade" id="selComsCfmModal">
        <div class="modal-dialog">
            <div class="modal-content message_align">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">×</span></button>
                    <h4 class="modal-title">未选择评论</h4>
                </div>
                <div class="modal-body">
                    <p>请选择您要删除的评论！</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a class="btn btn-success" data-dismiss="modal">确定</a>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <!-- 信息删除确认: For delete comments confirm -->
    <div class="modal fade" id="delComsCfmModel">
        <div class="modal-dialog">
            <div class="modal-content message_align">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">×</span></button>
                    <h4 class="modal-title">确认删除所选评论？</h4>
                </div>
                <div class="modal-body">
                    <p>将评论删除后不可恢复，您确认要删除所选评论吗？</p>
                    <p>
                        （提示：如果您只是不想显示该评论内容，可以选择将其屏蔽，而不必删除。）
                    </p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a id="delComsCfm" class="btn btn-success" data-dismiss="modal">确定</a>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
<script src="/static/admin/js/post_manage.js"></script>
<script type="text/javascript">
jQuery(function($) {
    var oTable1 = $('#sample-table-2').dataTable( {
    "aoColumns": [
      { "bSortable": false },
      null, null,null, null, null,
      { "bSortable": false }
    ] } );


    $('table th input:checkbox').on('click' , function(){
        var that = this;
        $(this).closest('table').find('tr > td:first-child input:checkbox')
        .each(function(){
            this.checked = that.checked;
            $(this).closest('tr').toggleClass('selected');
        });

    });


    $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
    function tooltip_placement(context, source) {
        var $source = $(source);
        var $parent = $source.closest('table')
        var off1 = $parent.offset();
        var w1 = $parent.width();

        var off2 = $source.offset();
        var w2 = $source.width();

        if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
        return 'left';
    }
})
</script>
    <!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
 {%endblock content%}
